var DP_DEVICE_WARN = window.NameSpace || {};

DP_DEVICE_WARN.createWarnmon = function(divId, planeId) {
	var dom = document.getElementById(divId);
	DP_GL_WARN = echarts.init(dom);

	DP_DEVICE_WARN.loadWarn(planeId);

	return DP_GL_WARN;

}

DP_DEVICE_WARN.loadWarn = function(planeId) {
	DP_GL_WARN.hideLoading();
	var option = {
		color : [ '#00a1ff', '#ffae00', '#4ed852' ],
		tooltip : {
			trigger : 'item',
			formatter : function(params, ticket, callback) {
				var date = new Date(params.value[0]);
				data = date.getFullYear() + '-' + (date.getMonth() + 1) + '-'
						+ date.getDate() + ' ' + date.getHours() + '时'
						+ date.getMinutes() + '分';
				return data + '<br/>告警次数：' + params.value[1];
			}

		},
		legend : {
			x : 'right',
			y : '30',
			data : [ 'SERVER', 'CAP', 'CMT' ],
			textStyle : {
				color : '#666',
				fontSize : 9
			}

		},
		title : {
			text : '机载设备告警统计',
			x : 'left'
		},
		noDataLoadingOption : {
			text : '暂无数据',
			effect : 'bubble',
			effectOption : {
				effect : {
					n : 0
				}
			},
			textStyle : {
				fontSize : 24,
				fontWeight : 'bold'
			}
		},
		// calculable : true,
		grid : {
			y : 50,
			// y2 : 30,
			x : 50,
			x2 : 25
		},
		xAxis : [ {
			type : 'time'
		} ],
		yAxis : [ {
			type : 'value',
			name : '告警次数',
			axisLabel : {
				formatter : '{value}',
				textStyle : {
					color : '#666',
					fontSize : 8
				}
			}
		} ],
		series : [ {
			name : 'SERVER',
			type : 'line',
			data : [],
			showAllSymbol : true,
			smooth : false
		}, {
			name : 'CAP',
			type : 'line',
			data : [],
			showAllSymbol : true,
			smooth : true
		}, {
			name : 'CMT',
			type : 'line',
			data : [],
			showAllSymbol : true,
			smooth : true,

		} ]
	};

	var time = (new Date()).format('yyyy-MM-dd 00:00:00');
	$.ajax({
		url : "/device/loadWifiWarn",
		async : true,
		data : {
			"planeId" : planeId,
			"createTime" : time
		},
		success : function(data) {
			// x轴
			if (data != null) {

				var serverValues = [];
				var cmtValues = [];
				var capValues = [];
				for (var i = 0; i < data.length; i++) {
					var tmp = []
					tmp.push(Number(new Date(data[i]['create_time'])));
					tmp.push(Number(data[i]['serverwarn']));
					serverValues.push(tmp);

					tmp = []
					tmp.push(Number(new Date(data[i]['create_time'])));
					tmp.push(Number(data[i]['cmtwarn']));
					cmtValues.push(tmp);

					tmp = []
					tmp.push(Number(new Date(data[i]['create_time'])));
					tmp.push(Number(data[i]['capwarn']));
					capValues.push(tmp);
				}

				option.series[0].data = serverValues;
				option.series[1].data = capValues;
				option.series[2].data = cmtValues;
				DP_GL_WARN.setOption(option, true);
				// DP_GL_FLOW.hideLoading();
			}

		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			console.log('exception>>' + textStatus);
			// setTimeout(MainPage_Flow.loadFlow , mp_refresh_time);
		}
	});

}
